package com.dq.domain.record;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.section.SysSection;
import com.dq.domain.sys.user.user.StaffUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;

/**
 * @Author luchangtong
 * @Date 2019/11/20 16:07
 */
@Entity
@Data
@ApiModel("工资记录")
public class PayrollRecord extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("门店")
    @ManyToOne
    protected SysSection org;
    @ApiModelProperty("员工")
    @ManyToOne
    protected StaffUser staffUser;
    @ApiModelProperty("发放时间")
    protected Long sendTime;
    @ApiModelProperty("基本工资")
    protected BigDecimal baseSalary;
    @ApiModelProperty("业绩提成")
    protected BigDecimal RoyaltyAmount;
    @ApiModelProperty("服务提成")
    protected BigDecimal serviceAmount;
    @ApiModelProperty("随机奖励")
    protected BigDecimal randomAmount;
    @ApiModelProperty("专项奖励")
    protected BigDecimal rewardAmount;
    @ApiModelProperty("实发工资(本月总计)")
    protected BigDecimal totalAmount;
    @ApiModelProperty("状态")
    @Enumerated(EnumType.ORDINAL)
    protected PayrollStatus payrollStatus;

    public enum PayrollStatus{
        waitApproval("待审批"),
        waitConfirm("待确认"),
        ConfirmSuccess("已确认");
        String name;
        PayrollStatus(String name){
            this.name = name;
        }
    }

    @Data
    @ApiModel(value = "工资记录视图")
    public static class Vo implements VO {

    }
    @Data
    @ApiModel("门店工资单详情")
    public static class OrgPayrollRecordDetailVo{
        @ApiModelProperty("发放工资月份")
        protected String sendTime;
        @ApiModelProperty("员工姓名")
        protected String realCName;
        @ApiModelProperty("员工工号")
        protected String cardNo;
        @ApiModelProperty("基本工资")
        protected BigDecimal baseSalary;
        @ApiModelProperty("业绩提成")
        protected BigDecimal royaltyAmount;
        @ApiModelProperty("服务提成")
        protected BigDecimal serviceAmount;
        @ApiModelProperty("随机奖励")
        protected BigDecimal randomAmount;
        @ApiModelProperty("专项奖励")
        protected BigDecimal rewardAmount;
        @ApiModelProperty("实发工资(本月总计)")
        protected BigDecimal totalAmount;

    }

    @Data
    @ApiModel("门店工资单视图")
    public static class OrgPayrollRecordListVo{
        @ApiModelProperty("工资单id")
        protected Long id;
        @ApiModelProperty("门店名")
        protected String orgName;
        @ApiModelProperty("员工姓名")
        protected String realCName;
        @ApiModelProperty("员工工号")
        protected String cardNo;
        @ApiModelProperty("基本工资")
        protected BigDecimal baseSalary;
        @ApiModelProperty("业绩提成")
        protected BigDecimal royaltyAmount;
        @ApiModelProperty("服务提成")
        protected BigDecimal serviceAmount;
        @ApiModelProperty("随机奖励")
        protected BigDecimal randomAmount;
        @ApiModelProperty("专项奖励")
        protected BigDecimal rewardAmount;
        @ApiModelProperty("实发工资(本月总计)")
        protected BigDecimal totalAmount;
        @ApiModelProperty("状态")
        protected String statusCN ;
        @ApiModelProperty("状态")
        protected PayrollStatus statusEN ;
        @ApiModelProperty("发放工资月份")
        protected String sendTime;
        @ApiModelProperty("提交时间")
        protected String createTime;
    }

    public OrgPayrollRecordDetailVo toOrgPayrollRecordDetailVo(){
        PayrollRecord.OrgPayrollRecordDetailVo orgPayrollRecordDetailVo = new PayrollRecord.OrgPayrollRecordDetailVo();
        orgPayrollRecordDetailVo.sendTime = fmt(this.getSendTime(),TimeUtil.YYYY_MM);
        orgPayrollRecordDetailVo.realCName = fmt(this.getStaffUser().getUserRealcName());
        orgPayrollRecordDetailVo.cardNo = fmt(this.getStaffUser().getCardNo());
        orgPayrollRecordDetailVo.baseSalary = fmt(this.getStaffUser().getBaseSalary());
        orgPayrollRecordDetailVo.royaltyAmount = fmt(this.getRoyaltyAmount());
        orgPayrollRecordDetailVo.rewardAmount = fmt(this.getRewardAmount());
        orgPayrollRecordDetailVo.randomAmount = fmt(this.getRandomAmount());
        orgPayrollRecordDetailVo.serviceAmount = fmt(this.getServiceAmount());
        orgPayrollRecordDetailVo.totalAmount = fmt(this.getTotalAmount());
        return orgPayrollRecordDetailVo;
    }


    public OrgPayrollRecordListVo toOrgPayrollRecordListVo(){
        PayrollRecord.OrgPayrollRecordListVo orgPayrollRecordListVo = new PayrollRecord.OrgPayrollRecordListVo();
        orgPayrollRecordListVo.id = this.getId();
        orgPayrollRecordListVo.orgName = this.getOrg().getSimpleName();
        orgPayrollRecordListVo.realCName = fmt(this.getStaffUser().getUserRealcName());
        orgPayrollRecordListVo.cardNo = fmt(this.getStaffUser().getCardNo());
        orgPayrollRecordListVo.baseSalary = fmt(this.getBaseSalary());
        orgPayrollRecordListVo.royaltyAmount = fmt(this.getRoyaltyAmount());
        orgPayrollRecordListVo.serviceAmount = fmt(this.getServiceAmount());
        orgPayrollRecordListVo.rewardAmount = fmt(this.getRewardAmount());
        orgPayrollRecordListVo.randomAmount = fmt(this.getRandomAmount());
        orgPayrollRecordListVo.totalAmount = fmt(this.getTotalAmount());
        orgPayrollRecordListVo.statusCN = fmt(this.getPayrollStatus().name);
        orgPayrollRecordListVo.statusEN = this.getPayrollStatus();
        orgPayrollRecordListVo.sendTime = fmt(this.getSendTime(),TimeUtil.YYYY_MM);
        orgPayrollRecordListVo.createTime = fmt(this.getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return orgPayrollRecordListVo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        return vo;
    }
}
